package com.solution.admin.customer.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.solution.admin.customer.dao.CompanyDao;
import com.solution.admin.customer.entity.CompanyAddressExtendEntity;
import com.solution.admin.customer.entity.CompanyEntity;
import com.solution.common.dao.impl.BaseDaoImpl;
import com.solution.common.page.PageBean;
import com.solution.common.page.PageParam;

/**
 * 单位信息DAO实现
 * @author solin
 * @date 2017-09-25 00:11:38
 */
@Repository
public class CompanyDaoImpl extends BaseDaoImpl<CompanyEntity> implements CompanyDao {
	
	@Autowired
	private SqlSessionTemplate sessionTemplate;

	/**
	 * 保存单位信息信息
	 * @param companyEntity
	 * @return
	 * @author solin
	 * @date 2017-09-25 00:11:38
	 */
	@Override
	public long saveCompany(CompanyEntity companyEntity) {
		return super.insert(companyEntity);
	}

	/**
	 * 分页查询单位信息信息
	 * @param pageParam 分页对象
	 * @param company 分页参数
	 * @return PageBean 分页参数及数据
	 * @author solin
	 * @date 2017-09-25 00:11:38
	 */
	public PageBean listCompanyPage(PageParam pageParam, Map<String, Object> param) {
		return super.listPage(pageParam, param);
	}

	/**
	 * 更新单位信息
	 * @param companyEntity
	 * @return
	 * @author solin
	 * @date 2017-09-25 00:11:38
	 */
	@Override
	public int updateCompany(CompanyEntity companyEntity) {
		return super.update(companyEntity);
	}

	/**
	 * 删除单位信息
	 * @param companyId
	 * @return
	 * @author solin
	 * @date 2017-09-25 00:11:38
	 */
	public int deleteCompanyById( Long id) {
		return super.deleteById(id);
	}
	
	/**
	 * 根据条件查询单位信息
	 * @param param
	 * @return
	 * @author solin
	 * @date 2017-09-25 00:11:38
	 */
	@Override
	public List<CompanyEntity> listCompany( Map<String, Object> param) {
		return super.listBy(param);
	}
	
	@Override
	public int insertAddress(List<CompanyAddressExtendEntity> list) {
		return sessionTemplate.insert(getStatement("insertAddress"), list);
	}
	
	@Override
	public int deleteAddressByCompanyId(Long id) {
		return sessionTemplate.delete(getStatement("deleteAddressByCompanyId"), id);
	}

    /**
     * 根据公司ID获取业务员信息
     * @param companyId
     * @return
     * @author xkl
     * @date 2018年2月9日 下午5:13:38
     */
	@Override
	public Map<String, Object> getSalesmanByCompanyId(Long companyId) {
		return sessionTemplate.selectOne(getStatement("getSalesmanByCompanyId"), companyId);
	}
}
